﻿package app.controller
{
	import org.osflash.thunderbolt.Logger;
    import org.puremvc.as3.interfaces.ICommand;
    import org.puremvc.as3.interfaces.INotification;
    import org.puremvc.as3.patterns.command.SimpleCommand;
    import app.facade.App;
	import app.model.proxy.*;
	import app.view.mediator.StageMediator;				
	import app.facade.EApp;

    public class LoadingCommand extends SimpleCommand implements ICommand {
		/**
		 * Notice: sequential marking!
		 * [1] tạo bộ chộn dữ liệu từ trong proxy khi hai dữ liệu đã được load xong
		 * [2] gửi lệnh load asset
		 * @param	note
		 */
	    override public function execute( note:INotification ):void {
			 switch (note.getName()) {
				case App.LOAD_PROXY_DONE:
					var app:AppProxy = facade.retrieveProxy(AppProxy.NAME) as AppProxy;
						app.loadedProxy(String(note.getBody()));
					if (app.isCompleted()) {
						//[1]
						sendNotification(App.LOADING_ASSET);
					}
				break;
				case App.LOADING_PROXY_ALL:
					AppProxy(facade.retrieveProxy(AppProxy.NAME)).load();
					ConfigProxy(facade.retrieveProxy(ConfigProxy.NAME)).load();
				break;
				case App.INIT_LOAD_DATA_PROXY:
					sendNotification(App.INIT_APPLICATION);	
					sendNotification(App.LOADING_SHOW);
				break;
			 }
        }
    }
}